Turn on more accessible mode
Skip Ribbon Commands
Skip to main content
Checking if a Feature License Exists

For internal applications, checking for licenses is probably not needed very often. When developing a MarketPlace app, developers are given a license that they can use in their application. Then, when a customer purchases an application from the MarketPlace, they are given the license for that application for their CIC server. When checking for the license a list of LicenseRequests need to be set to the server using the LicenseManagement class. The result set from the PerformLicenseOperation method is a list of responses, those responses indicate if the license is available or not.

1
2
3
4
5
6
7
8
static bool HasLicense(Session session, string licenseKey)
{
     LicenseRequest request = new LicenseRequest(licenseKey, LicenseRequestType.Query);
     LicenseManagement licenseManagement = new LicenseManagement(PeopleManager.GetInstance(session));
     List<LicenseRequest> licensesToCheck = new List<LicenseRequest>(new[] { request });
     ReadOnlyCollection<PerformLicenseOperationResult> licenseResults = licenseManagement.PerformLicenseOperation(licensesToCheck);
     return licenseResults[0].IsAvailable;
}

Using this code to call into the method, we get a result of

analyzer: True
invalid: False

 

1
2
3
4
5
6
7
8
9
static void Main(string[] args)
{
     Session session = new Session();
     session.Connect(new SessionSettings(), new HostSettings(new HostEndpoint("morbo")), new WindowsAuthSettings(), new StationlessSettings());
     Console.WriteLine("analyzer: " + HasLicense(session, "I3_FEATURE_ANALYZER"));
     Console.WriteLine("invalid: " + HasLicense(session, "I_MADE_THIS_LICENSE_UP"));
     Console.ReadLine();
}
        

At the time of writing this, only feature licenses are available and not user licenses, but in case someone needs to check the user's license here's how to do it.  You can check for a user's license and then enable/disable features in your app based on the license. Checking to see if a user has a license is a little simpler.

1
2
3
4
5
6
static bool UserHasLicense(Session session, string licenseKey)
{
     LicenseManagement licenseManagement = new LicenseManagement(PeopleManager.GetInstance(session));
     bool isLicensed = licenseManagement.IsLicenseAssigned(licenseKey);
     return isLicensed;
}



​​​​